<?php
namespace app\hotel\model;

use think\Model;
use think\Db;
use think\Session;

class Room extends Model
{

    static function getRoomKindsList($where = array()){  
        $hotel_id = Session::get('hotel_id'); 
            $where=['hr.hotel_id'=>$hotel_id,'hr.is_del'=>0];
            $data = Db::name('hotel')
            ->alias('h')
            ->join('hotel_room hr','hr.hotel_id=h.hotel_id','left')
            ->where($where)
             ->order('sort desc,room_id desc')
            ->select();
        return $data;
    }

    static function getOlnyDataNameList(){
        $result['room'] = Db::name('datas')->field("id,data_name")->where('type_id',1)->select();
        $result['assort'] = Db::name('datas')->field("id,data_name")->where('type_id',2)->select();
        $result['catering'] = Db::name('datas')->field("id,data_name")->where('type_id',3)->select();
        if(count($result)>0){
            return $result;
        }
    }

    static function getOlnyRoomKindsList($field){
        $hotel_id = Session::get('hotel_id');
        $data = Db::name('hotel_room')
            ->field($field)
            ->where('hotel_id',$hotel_id)
           // ->order('sort desc,room_id desc')
            ->order('room_id desc')
            ->select();

        return $data;
    }

    static function editRoomKinds($id,$data){ 
        Db::name('hotel_room')->where('room_id',$id)->update($data); 
 
    }
      static function delRoom($id){

        
        return Db::name('hotel_room')->where('room_id',$id)->update(['is_del'=>1]);
       

    }
    

    static function getRoomImgList($room_id,$isCount){

        $query = Db::name('room_img')->where('room_id',$room_id);

        if ($isCount){
            return $query->count();
        }else{
            return $query->select();
        }

    }

    static function getRoomList($where,$startrow = 0, $pageSize = 0,$isCount){

        $hotel_id = Session::get('hotel_id');
        $query = Db::name('hotel_eroom')->alias('t1')
                    ->field('t1.room_id,eroom_id,t1.room_id,t2.room_name,t1.room_number,t1.is_ruzhu,remarks,t1.remarks') 
                    ->join('lv_hotel_room t2','t1.room_id = t2.room_id','left')
                    ->where('t2.hotel_id',$hotel_id)
                    ->where($where);

        if ($isCount){
            return $query->count();
        }

        if ($pageSize){
            return $query
                ->order('room_id desc')
                ->limit($startrow,$pageSize)
                ->select();

        }else{
            return $query
                ->order('room_id desc')
                ->select();
        }

    }

    static function editRoom($id,$editData){ 
        return Db::name('hotel_eroom')->where('eroom_id',$id)->update($editData); 

    }
}